home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / EVENTLST / HOOKDBTN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-05-12  |  1.8 KB  |  78 lines

  1. { *****************************************************
  2.                          THookButton Component
  3.  
  4.   A trivial example of a component with a TEventList. 
  5.  
  6.                     Paul Warren
  7.            HomeGrown Software Development
  8.          (c) 1997 Langley British Columbia.
  9.                   (604) 856-6523
  10.            e-mail:  hg_soft@uniserve.com
  11.      Home page: http://users.uniserve.com/~hg_soft
  12.   ***************************************************** }
  13.  
  14. unit Hookdbtn;
  15.  
  16. interface
  17.  
  18. uses
  19.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  20.   Forms, Dialogs, Buttons, EList;
  21.  
  22. type
  23.   THookedButton = class(TSpeedButton)
  24.   private
  25.     { private declarations }
  26.     FEventList: TEventList;
  27.     FHookEvent: TNotifyEvent;
  28.     procedure SetHookEvent(Value: TNotifyEvent);
  29.   protected
  30.     { protected declarations }
  31.     procedure Click; override;
  32.   public
  33.     { public declarations }
  34.     constructor Create(AOwner: TComponent); override;
  35.     destructor Destroy; override;
  36.     property HookEvent: TNotifyEvent write SetHookEvent;
  37.   published
  38.     { published declarations }
  39.   end;
  40.  
  41. procedure Register;
  42.  
  43. implementation
  44.  
  45. constructor THookedButton.Create(AOwner: TComponent); 
  46. begin
  47.   inherited Create(AOwner);
  48.   FEventList := TEventList.Create;
  49. end;
  50.  
  51. destructor THookedButton.Destroy; 
  52. begin
  53.   FEventList.Free;
  54.   inherited Destroy;
  55. end;
  56.  
  57. procedure THookedButton.SetHookEvent(Value: TNotifyEvent);
  58. begin
  59.   FEventList.AddEvent(Value);
  60. end;
  61.  
  62. procedure THookedButton.Click;
  63. var
  64.   i: integer; 
  65. begin
  66.   inherited Click;
  67.   for i := 0 to FEventList.Count-1 do
  68.   begin
  69.     FHookEvent := FEventList.Events[i];
  70.     FHookEvent(Self);
  71.   end;
  72. end;
  73.  
  74. { register component on Samples page }
  75. procedure Register;
  76. begin
  77.   RegisterComponents('Samples', [THookedButton]);
  78. end;
  79.  
  80. end.